package com.itheima.prize.commons.db.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.prize.commons.db.entity.CardGameProduct;
import com.itheima.prize.commons.db.entity.CardProduct;
import com.itheima.prize.commons.db.entity.CardProductDto;
import com.itheima.prize.commons.db.mapper.CardGameProductMapper;
import com.itheima.prize.commons.db.service.CardProductService;
import com.itheima.prize.commons.db.mapper.CardProductMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author shawn
* @description 针对表【card_product】的数据库操作Service实现
* @createDate 2023-12-26 11:58:48
*/
@Service
public class CardProductServiceImpl extends ServiceImpl<CardProductMapper, CardProduct>
    implements CardProductService{
@Autowired
private CardProductMapper cardProductMapper;
@Autowired
private CardGameProductMapper cardGameProductMapper;
    @Override
    public List<CardProductDto> searchProductInfo(int gameid) {
        LambdaQueryWrapper<CardGameProduct> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(CardGameProduct::getGameid,gameid);
        List<CardProductDto> cardProductDtoList=new ArrayList<>();
        List<CardGameProduct> cardGameProducts = cardGameProductMapper.selectList(wrapper);
        cardGameProducts.forEach(cardGameProduct -> {
            CardProduct cardProduct = cardProductMapper.selectById(cardGameProduct.getProductid());
            CardProductDto cardProductDto=new CardProductDto();
            cardProductDto.setAmount(cardGameProduct.getAmount());
            BeanUtils.copyProperties(cardProduct,cardProductDto);
            cardProductDtoList.add(cardProductDto);
        });

        return cardProductDtoList;
    }
}




